package com.st.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.st.domain.StTeachers;
import com.st.service.IStTeachersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 讲师Controller
 * 
 * @author zhw
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/st/teachers")
public class StTeachersController extends BaseController
{
    @Autowired
    private IStTeachersService stTeachersService;

    /**
     * 查询讲师列表
     */
    @PreAuthorize("@ss.hasPermi('st:teachers:list')")
    @GetMapping("/list")
    public TableDataInfo list(StTeachers stTeachers)
    {
        startPage();
        List<StTeachers> list = stTeachersService.selectStTeachersList(stTeachers);
        return getDataTable(list);
    }

    /**
     * 导出讲师列表
     */
    @PreAuthorize("@ss.hasPermi('st:teachers:export')")
    @Log(title = "讲师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StTeachers stTeachers)
    {
        List<StTeachers> list = stTeachersService.selectStTeachersList(stTeachers);
        ExcelUtil<StTeachers> util = new ExcelUtil<StTeachers>(StTeachers.class);
        util.exportExcel(response, list, "讲师数据");
    }

    /**
     * 获取讲师详细信息
     */
    @PreAuthorize("@ss.hasPermi('st:teachers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(stTeachersService.selectStTeachersById(id));
    }

    /**
     * 新增讲师
     */
    @PreAuthorize("@ss.hasPermi('st:teachers:add')")
    @Log(title = "讲师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StTeachers stTeachers)
    {
        return toAjax(stTeachersService.insertStTeachers(stTeachers));
    }

    /**
     * 修改讲师
     */
    @PreAuthorize("@ss.hasPermi('st:teachers:edit')")
    @Log(title = "讲师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StTeachers stTeachers)
    {
        return toAjax(stTeachersService.updateStTeachers(stTeachers));
    }

    /**
     * 删除讲师
     */
    @PreAuthorize("@ss.hasPermi('st:teachers:remove')")
    @Log(title = "讲师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(stTeachersService.deleteStTeachersByIds(ids));
    }
}
